<?php

namespace api\toilet\logic;

use api\admin\model\BandToiletModel;
use api\admin\model\BandToiletTagModel;
use api\admin\model\ToiletFlowModel;
use api\toilet\util\Tools;

class DistanceModel
{
	/**
	 * [getDistance 根据类型获取当前公厕距离列表]
	 * @Author   HUI
	 * @DateTime 2020-02-04
	 * @version  [version]
	 * @param    [type]     $data [0--默认10km内,1--1km，2--3km,4--5km]
	 * @param    integer    $type [description]
	 * @return   [type]           [description]
	 */
	public function getToiletDistance($data,$longitude,$latitude,$type = 0)
	{
        $distance = config('distance');
        $tool = new Tools();
        // $type = 1;
        $toilet = [];
        //过滤数据
        foreach ($data as $key => $value) {
        	// print_r($value);exit();
        	$km = $tool->getDistance(
        		$value['latitude'],
        		$value['longitude'],
        		$latitude,
        		$longitude,
        	);
        	if (empty($value['latitude']) || empty($value['longitude']) || $km > $distance[$type]) {
        		continue;
        	}else{
        		$toilet[] = $value;
        	}
        }

       	return empty($toilet) ? null : $toilet;
	}

}